package hr.fer.zemris.revhttp.gateway;

import hr.fer.zemris.revhttp.gateway.websockets.ProxyServlet;
import hr.fer.zemris.revhttp.gateway.websockets.ServerInterfaceServlet;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;

/**
 * @author tomek
 */
public class GatewayRunner {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Server server = new Server(8080);

			ServletContextHandler context = new ServletContextHandler(
					ServletContextHandler.SESSIONS);
			context.setContextPath("/");

			context.addServlet(ServerInterfaceServlet.class, "/server");
			context.addServlet(ProxyServlet.class, "/apps/*");

			ResourceHandler resource_handler = new ResourceHandler();
			resource_handler.setResourceBase("./static_pages");
			HandlerList handlers = new HandlerList();
			resource_handler.setDirectoriesListed(true);
			handlers.setHandlers(new Handler[] { context,
					resource_handler, new DefaultHandler() });
			server.setHandler(handlers);

			// server.setHandler(context);
			server.start();
			server.join();
		} catch (Exception e) {
			System.err.println(e.getMessage());
			System.exit(1);
		}
	}

}
